﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;
using System.Windows.Forms;
using NLog;
using XCI.Core;
using XCI.Helper;

namespace XCI.Windows
{
    [FormCaption(false)]
    public partial class FrmException : BaseForm
    {
        /// <summary>
        /// 异常对象
        /// </summary>
        private System.Exception ExceptionInfo { get; set; }

        private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

        public FrmException()
        {
            InitializeComponent();
        }

        public FrmException(System.Exception e)
        {
            InitializeComponent();
            this.ExceptionInfo = e;
            Logger.Error(e);
        }

        private void ExceptionForm_Load(object sender, EventArgs e)
        {
            WinFormHelper.SetDateFormat(editCreateDateTime, true);
            App.ContainerData.ForEach(panel1, p =>
            {
                if (!(p is Control control)) return;
                control.BackColor = this.BackColor;
            });
            editIP.Text = NetHelper.GetLocalIP();
            editCreateDateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            editDetails.Text = DebugHelper.BuildAllStackTrace(ExceptionInfo);
        }

        private void btnCopyMessage_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(editDetails.Text);
            MessageBoxHelper.ShowMessage("异常信息已经复制到剪贴板!");
        }

        private void btnFeedback_Click(object sender, EventArgs e)
        {
            MessageBoxHelper.ShowMessage("信息已经反馈,工作人员会尽快修复为,感谢您的支持!");
            this.Close();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}